/**
 * 
 */
package abstractions;

import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Vector;

import static server.Server.*;


/**
 * @author rdru
 * INV: 
 */
public class OpenDoc2 extends Doc {		// used by the Client
	public int							id;			// docId
	protected String					text;		// contents of the document
	public LinkedList<Integer>			editedBy;	// <userId, Usr>
	public Vector<LinkedList<CommandC>>	histOld;
	public HashMap<AtomId, Integer>		locked;		// <AtomId, userId>
	public int							ups;		// # updates sent
	public int							upr;		// # updates recieved
	public int							n;			// total # Commands recieved
	
	public OpenDoc2(Doc d, String text) throws RemoteException {
		super(d.fileName, d.pathName, d.isRemote);
		this.text = text;
		this.id = nextDocId++;
		this.editedBy = new LinkedList<Integer>();
		this.histOld = new Vector<LinkedList<CommandC>>();
		this.locked = new HashMap<AtomId, Integer>();
		this.ups = 0;
		this.upr = 0;
		this.n = 0;
		
	}
	
	public void addUser(LoggedUser user) {
		editedBy.add(user.id);
	}
	
	public void removeUser(LoggedUser user) {
		if(editedBy.remove(user.id) == null) {
			// problems removing from editingUsers
		}
	}
}


